package com.service.impl.order;

import com.client.DadaApiResponse;
import com.client.DadaRequestClient;
import com.config.AppConfig;
import com.config.AppConstant;
import com.config.UrlConstant;
import com.entity.UrlParams;
import com.request.AddOrderReq;
import com.service.OrderAddService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 新增订单
 * @author zhang
 */
@Service
public class OrderAddServiceImpl implements OrderAddService {

    @Value("${spring.config.isOnline}")
    private Boolean IS_ONLINE;

    /**
     * 新增订单
     * @param addOrderReq
     * @return DadaApiResponse
     */
    @Override
    public DadaApiResponse orderAdd(AddOrderReq addOrderReq) {
        // 1.初始化配置(isOnline表示是否测试环境)
        AppConfig appConfig = new AppConfig(IS_ONLINE);
        appConfig.setOnline(IS_ONLINE);
        // 2.初始化客户端
        DadaRequestClient dadaClient = new DadaRequestClient(new UrlParams(UrlConstant.ORDER_ADD_URL, addOrderReq.toJson()), appConfig);
        DadaApiResponse dadaApiResponse = dadaClient.callRpc();
        return dadaApiResponse;
    }
}
